package com.twu.biblioteca.dao;

import com.twu.biblioteca.model.Book;
import com.twu.biblioteca.model.Movie;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by minggong on 7/18/14.
 */
public class MovieResource extends EntityResource{

    public MovieResource(String fileName) {
        super();
        readFile(fileName);
    }

    protected void readFile(String file) {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            String line;
            bufferedReader.readLine();//skip first title line.
            while((line = bufferedReader.readLine()) != null) {
                String[] content = line.split(",");
                if (content.length != 4) continue;
                entities.add(new Movie(generateId++, content[0], content[1], content[2], content[3]));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
